table.insert(itemActions,
   function(item, action)
      -- UNIQUE charms
      if not (item.quality == ItemQuality.Unique and
            (item.baseItem.code == "cm1" or
            item.baseItem.code == "cm2" or
            item.baseItem.code == "cm3")) then
         return false
      end

      return processItemList(item, action, uniqueCharms)
   end
)

--[[
-Be VERY careful when editing these, you don't want to be stuck picking
   a charm until you timeout.

-Note the importance of ItemActionType on gheeds.

-Also note that when you drop one from inventory, bot will not pick it up.
   (Good for if you are watching it and see gheeds drop, you can manually drop
   yours and pick the unid one, though this is not why the actiontype is there)

-You can include this file even if you already have gheeds,
   but it will not drop yours and see if an unid one is better.
   Yet. o.O (Feel free to help with this!)
]]--

-- see: dir .. "readme.txt" for information regarding itemLists

uniqueCharms = {
   {"cm1", 9, false}, -- Annihilus
   {"cm2", 9, false}, -- Hellfire Torch
   {"cm3", 7, true, -- Gheed's Fortune
      function(item)
         if item.action ~= ItemActionType.DropToGround then -- we don't have one already
            if item.flags.Identified then
               return isGoodGheeds(item)
            elseif not item.flags.Identified then
               return true -- unid
            end
         else
            return false -- we already have one
         end
      end
   }
}

function isGoodGheeds(item)
   local mf, gf, rvp = 0, 0, 0
   
   for i = 0, item.mods:size() - 1 do
      if item.mods[i].Stat.Type == StatType.GoldFind then
         gf = item.mods[i].Value
      elseif item.mods[i].Stat.Type == StatType.MagicFind then
         mf = item.mods[i].Value
      elseif item.mods[i].Stat.Type == StatType.ReducedPrices then
         rvp = item.mods[i].Value
      end
   end
   
   return (mf >= 5) or ((gf >= 10) or (rvp >= 10)) -- 40-160-15 perf mf and (perf gold or perf vendor)
end
